<template>
  <div>
    <div class="bg-white grid-content">
      <div style="overflow: hidden">
        <div class="mytitle">
          <svg-icon icon-class="yjbb" class="myIcon" /> 产量情况
        </div>
        <div class="myButtons">
          <el-button
            @click="handleClick('', 'add')"
            v-if="hasPermission('sys:sjtb:scgl:clqk:add')"
            >新增</el-button
          >
          <el-button
            class="import-button"
            icon="el-icon-upload2"
            @click="uploadFiles"
            v-if="hasPermission('sys:sjtb:scgl:clqk:import')"
          >
            <i class="icon"></i>
            批量导入
          </el-button>
          <el-dialog
            title="批量导入"
            :visible.sync="importDialog"
            class="dialog-md"
            width="500px"
            :before-close="handleClose1"
          >
            <el-form
              ref="fileForm"
              label-position="center"
              style="width: 100%"
              enctype="multipart/form-data"
            >
              <el-form-item align="center" label="">
                <el-upload
                  ref="upload"
                  class="uploadDialog"
                  name="myfile"
                  action="string"
                  :http-request="httpRequest"
                  :on-change="handleChange"
                  :on-remove="handleRemove"
                  :before-remove="handleBeforeRemove"
                  :limit="1"
                  :file-list="fileList"
                  accept=".xlsx,.xls"
                  :auto-upload="true"
                >
                  <el-button slot="trigger" size="small" type="primary"
                    >上传文件</el-button
                  >
                  <div class="el-upload__tip">1.仅支持上传.xls、.xlsx文件</div>
                  <div class="el-upload__tip">2.文件数据不能超过1000条</div>
                </el-upload>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button size="small" @click="cancelUpload()">取消</el-button>
              <el-button
                type="primary"
                size="small"
                @click="upload()"
                :disabled="uploading"
                >确定导入</el-button
              >
            </span>
          </el-dialog>
        </div>
      </div>
      <!-- 表格 -->
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :header-cell-style="{ background: '#F5F7FA', color: '#909399' }"
        stripe
      >
        <el-table-column align="center" prop="" label="<<">
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="date" label="日期">
            </el-table-column>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center" prop="compony" label="公司">
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="gsGsjh" label="公司计划">
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="gsGsws" label="公司外输">
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="gsGshs" label="公司核实">
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="gsGsend" label="公司末端">
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="gsCz" label="差值">
            </el-table-column>
          </el-table-column>
          <el-table-column align="center" prop="" label="">
            <el-table-column align="center" prop="gsEnd" label="末端">
            </el-table-column>
          </el-table-column>
        </el-table-column>
        <el-table-column align="center" prop="scdw" label="生产单位">
          <el-table-column align="center" prop="yq" label="一区">
            <el-table-column align="center" prop="yqPlan" label="计划">
            </el-table-column>
            <el-table-column align="center" prop="yqEnd" label="末端">
            </el-table-column>
            <el-table-column align="center" prop="yqPercent" label="百分比">
            </el-table-column>
            <el-table-column align="center" prop="yqFt" label="分摊">
            </el-table-column>
            <el-table-column align="center" prop="yqHsh" label="核实后">
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" prop="eq" label="二区">
            <el-table-column align="center" prop="eqPlan" label="计划">
            </el-table-column>
            <el-table-column align="center" prop="eqEnd" label="末端">
            </el-table-column>
            <el-table-column align="center" prop="eqPercent" label="百分比">
            </el-table-column>
            <el-table-column align="center" prop="eqFt" label="分摊">
            </el-table-column>
            <el-table-column align="center" prop="eqHsh" label="核实后">
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" prop="sanq" label="三区">
            <el-table-column align="center" prop="sanqPlan" label="计划">
            </el-table-column>
            <el-table-column align="center" prop="sanqEnd" label="末端">
            </el-table-column>
            <el-table-column align="center" prop="sanqPercent" label="百分比">
            </el-table-column>
            <el-table-column align="center" prop="sanqFt" label="分摊">
            </el-table-column>
            <el-table-column align="center" prop="sanqHsh" label="核实后">
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" prop="siq" label="四区">
            <el-table-column align="center" prop="siqPlan" label="计划">
            </el-table-column>
            <el-table-column align="center" prop="siqEnd" label="末端">
            </el-table-column>
            <el-table-column align="center" prop="siqPercent" label="百分比">
            </el-table-column>
            <el-table-column align="center" prop="siqFt" label="分摊">
            </el-table-column>
            <el-table-column align="center" prop="siqHsh" label="核实后">
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" prop="wq" label="五区">
            <el-table-column align="center" prop="wqPlan" label="计划">
            </el-table-column>
            <el-table-column align="center" prop="wqEnd" label="末端">
            </el-table-column>
            <el-table-column align="center" prop="wqCz" label="差值">
            </el-table-column>
            <el-table-column align="center" prop="wqHsh" label="核实后">
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" prop="zz" label="肇州">
            <el-table-column align="center" prop="zzPlan" label="计划">
            </el-table-column>
            <el-table-column align="center" prop="zzEnd" label="末端">
            </el-table-column>
            <el-table-column align="center" prop="zzCz" label="差值">
            </el-table-column>
            <el-table-column align="center" prop="zzHsh" label="核实后">
            </el-table-column>
          </el-table-column>

          <el-table-column align="center" prop="compony1" label="公司">
            <el-table-column align="center" prop="gsLdy" label="落地油">
            </el-table-column>
          </el-table-column>
        </el-table-column>

        <el-table-column
          align="center"
          fixed="right"
          prop="approveStatus"
          label="审核状态"
        >
          <template slot-scope="scope">
            <el-tooltip
              :content="scope.row.approveBz"
              placement="bottom"
              effect="light"
              :disabled="!scope.row.approveBz"
            >
              <el-badge
                :is-dot="scope.row.approveBz || scope.row.approveBz === ' '"
                class="item"
              >
                <el-tag
                  :class="scope.row.approveBz ? 'tagstyle' : ''"
                  :type="
                    scope.row.approveStatus == '2'
                      ? 'success'
                      : scope.row.approveStatus == '1'
                      ? 'warning'
                      : scope.row.approveStatus == '0'
                      ? 'info'
                      : 'danger'
                  "
                  disable-transitions
                  >{{
                    scope.row.approveStatus == "2"
                      ? "已通过"
                      : scope.row.approveStatus == "1"
                      ? "未审核"
                      : scope.row.approveStatus == "0"
                      ? "未提交"
                      : "未通过"
                  }}</el-tag
                >
              </el-badge>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          fixed="right"
          label="操作"
          width="140"
          v-if="
            hasPermission('sys:sjtb:scgl:clqk:edit') ||
            hasPermission('sys:sjtb:scgl:clqk:check')
          "
        >
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row, 'check')"
              type="text"
              v-if="hasPermission('sys:sjtb:scgl:clqk:check')"
              >查看</el-button
            >
            <el-button
              @click="handleClick(scope.row, 'edit')"
              type="text"
              v-if="hasPermission('sys:sjtb:scgl:clqk:edit')"
              >编辑</el-button
            >
            <el-button
              @click="handleDelete(scope.row)"
              type="text"
              style="color: red"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        align="right"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="[5, 10, 20, 30, 40, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 弹出框 -->
    <el-dialog
      :title="myDialogTitle"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
      custom-class="saveAsDialog"
    >
      <el-form
        :inline="true"
        :model="clqkForm"
        class="demo-form-inline"
        :rules="rules"
        ref="clqkForm"
        :disabled="isInput"
        label-position="left"
        label-width="190px"
      >
        <!-- <el-divider content-position="left">基础信息</el-divider> -->
        <el-divider content-position="left">基本信息</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-input
                v-model="clqkForm.date"
                placeholder="请输入日期"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">公司数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司计划">
              <el-input
                v-model="clqkForm.gsGsjh"
                placeholder="请输入公司计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司外输">
              <el-input
                v-model="clqkForm.gsGsws"
                placeholder="请输入公司外输数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="公司核实">
              <el-input
                v-model="clqkForm.gsGshs"
                placeholder="请输入公司核实数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司末端">
              <el-input
                v-model="clqkForm.gsGsEnd"
                placeholder="请输入公司末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="差值">
              <el-input
                v-model="clqkForm.gsCz"
                placeholder="请输入差值数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.gsEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">生产单位数据</el-divider>
        <el-divider content-position="left">一区数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划">
              <el-input
                v-model="clqkForm.yqPlan"
                placeholder="请输入计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.yqEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="百分比">
              <el-input
                v-model="clqkForm.yqPercent"
                placeholder="请输入百分比"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分摊">
              <el-input
                v-model="clqkForm.yqFt"
                placeholder="请输入分摊数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="核实后">
              <el-input
                v-model="clqkForm.yqHsh"
                placeholder="请输入核实后的数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">二区数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划">
              <el-input
                v-model="clqkForm.eqPlan"
                placeholder="请输入计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.eqEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="百分比">
              <el-input
                v-model="clqkForm.eqPercent"
                placeholder="请输入百分比"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分摊">
              <el-input
                v-model="clqkForm.eqFt"
                placeholder="请输入分摊数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="核实后">
              <el-input
                v-model="clqkForm.eqHsh"
                placeholder="请输入核实后的数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">三区数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划">
              <el-input
                v-model="clqkForm.sanqPlan"
                placeholder="请输入计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.sanqEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="百分比">
              <el-input
                v-model="clqkForm.sanqPercent"
                placeholder="请输入百分比"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分摊">
              <el-input
                v-model="clqkForm.sanqFt"
                placeholder="请输入分摊数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="核实后">
              <el-input
                v-model="clqkForm.sanqHsh"
                placeholder="请输入核实后的数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">四区数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划">
              <el-input
                v-model="clqkForm.siqPlan"
                placeholder="请输入计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.siqEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="百分比">
              <el-input
                v-model="clqkForm.siqPercent"
                placeholder="请输入百分比"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分摊">
              <el-input
                v-model="clqkForm.siqFt"
                placeholder="请输入分摊数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="核实后">
              <el-input
                v-model="clqkForm.siqHsh"
                placeholder="请输入核实后的数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">五区数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划">
              <el-input
                v-model="clqkForm.wqPlan"
                placeholder="请输入计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.wqEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="差值">
              <el-input
                v-model="clqkForm.wqCz"
                placeholder="请输入差值"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="核实后">
              <el-input
                v-model="clqkForm.wqHsh"
                placeholder="请输入核实后的数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">肇州数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计划">
              <el-input
                v-model="clqkForm.zzPlan"
                placeholder="请输入计划数据"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="末端">
              <el-input
                v-model="clqkForm.zzEnd"
                placeholder="请输入末端数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="差值">
              <el-input
                v-model="clqkForm.zzCz"
                placeholder="请输入差值"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="核实后">
              <el-input
                v-model="clqkForm.zzHsh"
                placeholder="请输入核实后的数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">公司数据</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="落地油">
              <el-input
                v-model="clqkForm.gsLdy"
                placeholder="请输入落地油数据"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer" v-show="!ischeck">
        <el-button @click="close('clqkForm')">取 消</el-button>
        <el-button type="primary" @click="submitForm('clqkForm')"
          >确 定</el-button
        >
      </div>
      <div slot="footer" class="dialog-footer" v-show="ischeckSh">
        <el-button type="primary" @click="submitSh('clqkForm')"
          >提交审核</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import clqkApi from "@/api/clqk";
import { getToken } from "@/utils/auth";

export default {
  data() {
    return {
      pageNo: 1, //当前页码
      pageSize: 10, //每页显示数量
      total: 0, //总数量
      // table数据
      tableData: [
        {
          compony: "string",
          date: "string",
          eqEnd: 0,
          eqFt: 0,
          eqHsh: 0,
          eqPercent: 0,
          eqPlan: 0,
          gsCz: 0,
          gsEnd: 0,
          gsGsend: 0,
          gsGshs: 0,
          gsGsjh: 0,
          gsGsws: 0,
          gsLdy: 0,
          id: 0,
          date: "2023-03-24T06:28:30.795Z",
          sanqEnd: 0,
          sanqFt: 0,
          sanqHsh: 0,
          sanqPercent: 0,
          sanqPlan: 0,
          scdw: "string",
          siqEnd: 0,
          siqFt: 0,
          siqHsh: 0,
          siqPercent: 0,
          siqPlan: 0,
          wqCz: 0,
          wqEnd: 0,
          wqHsh: 0,
          wqPlan: 0,
          yqEnd: 0,
          yqFt: 0,
          yqHsh: 0,
          yqPercent: 0,
          yqPlan: 0,
          zzCz: 0,
          zzEnd: 0,
          zzHsh: 0,
          zzPlan: 0,
        },
      ],
      //当前页码
      currentPage: 1,
      //表单填报的数据
      clqkForm: {
        id: "",
        approveStatus: "", //审核状态
        compony: "string",
        date: "string",
        eqEnd: 0,
        eqFt: 0,
        eqHsh: 0,
        eqPercent: 0,
        eqPlan: 0,
        gsCz: 0,
        gsEnd: 0,
        gsGsend: 0,
        gsGshs: 0,
        gsGsjh: 0,
        gsGsws: 0,
        gsLdy: 0,
        id: 0,
        date: "2023-03-24T06:28:30.795Z",
        sanqEnd: 0,
        sanqFt: 0,
        sanqHsh: 0,
        sanqPercent: 0,
        sanqPlan: 0,
        scdw: "string",
        siqEnd: 0,
        siqFt: 0,
        siqHsh: 0,
        siqPercent: 0,
        siqPlan: 0,
        wqCz: 0,
        wqEnd: 0,
        wqHsh: 0,
        wqPlan: 0,
        yqEnd: 0,
        yqFt: 0,
        yqHsh: 0,
        yqPercent: 0,
        yqPlan: 0,
        zzCz: 0,
        zzEnd: 0,
        zzHsh: 0,
        zzPlan: 0,
      },
      //验证规则
      rules: {
        syjmc: [
          { required: true, message: "请输入水源井名称", trigger: "blur" },
        ],
        ssdw: [{ required: true, message: "请输入所属单位", trigger: "blur" }],
        tcrq: [{ required: true, message: "请选择日期", trigger: "change" }],
      },
      //时间快捷选择
      pickerOptions: {
        // disabledDate(time) {
        //   return time.getTime() > Date.now();
        // },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      //获取当前日期
      currentTime: "",
      //编辑框是否显示
      dialogFormVisible: false,
      //弹出框是否是查看
      ischeck: false,
      //弹出框是否有提交审核按钮
      ischeckSh: false,
      //控制查看时不可更改数据
      isInput: false,
      //弹出框标题
      myDialogTitle: "",

      file: null,
      //加载动画
      uploadLoading: false,
      //上传的文件列表
      fileList: [],
      //控制弹出框显示与否
      uploadShowDialog: false,
      //上传地址
      uploadURL: "",
      //loading加载中
      downloadLoading: "",
      importDialog: false,
      fileList: [],
      urlFile: "",
      uploading: true,
    };
  },
  created() {
    this.search();
  },
  mounted() {
    this.filterTime();
    // this.initDate();
  },
  methods: {
    /**
     * 查询列表
     */
    async search() {
      // this.pageNo = pageNo; //当前页码
      // this.pageSize = pageSize; //每页显示数量
      //发送查询请求
      let res = await clqkApi.getClqkList(this.pageNo, this.pageSize);
      //判断是否成功
      if (res.success) {
        console.log(res.data);
        //赋值
        this.tableData = res.data.records;
        //总数量
        this.total = res.data.total;
      }
    },
    onSubmit() {
      console.log("submit!");
    },
    //关闭对话框
    handleClose(done) {
      // 清空表单
      // this.$refs['clqkForm'].resetFields();
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs["clqkForm"].clearValidate();
      done();
    },
    handleClose1(done) {
      this.urlFile = "";
      this.fileList = [];
      done();
    },
    // 弹框关闭触发
    close(formName) {
      this.dialogFormVisible = false;
      // 清空表单
      // this.$refs[formName].resetFields();
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs[formName].clearValidate();
    },

    submitForm(formName) {
      //表单验证
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let res = null;
          console.log(this.clqkForm.id + "111");
          //判断菜单ID是否为空
          if (this.clqkForm.id === "") {
            this.clqkForm.rq = this.currentTime;
            //发送添加请求
            res = await clqkApi.addClqk(this.clqkForm);
          } else {
            //发送修改请求
            this.clqkForm.approveStatus = 0;
            // console.log(334345)
            res = await clqkApi.updateClqk(this.clqkForm);
          }
          console.log(res);
          //判断是否成功
          if (res.success) {
            this.$message.success(res.message);
            //刷新
            this.search();
            //关闭窗口
            this.dialogFormVisible = false;
          } else {
            console.log(res);
            this.$message.error(res.message);
          }
        }
      });
    },
    //提交审核
    async submitSh(formName) {
      let res = null;
      //发送修改请求
      this.clqkForm.approveStatus = 1;
      this.clqkForm.approveBz = "";
      // console.log(334345)
      res = await clqkApi.updateClqk(this.clqkForm);

      console.log(res);
      //判断是否成功
      if (res.success) {
        this.$message.success(res.message);
        //刷新
        this.search();
        //关闭窗口
        this.dialogFormVisible = false;
      } else {
        console.log(res);
        this.$message.error(res.message);
      }
    },
    handleClick(row, handle) {
      // console.log(row.approveStatus);
      this.dialogFormVisible = true;
      if (handle == "check") {
        this.myDialogTitle = "产量情况报表";
        if (row.approveStatus == 0) {
          this.ischeckSh = true;
        } else {
          this.ischeckSh = false;
        }
        this.ischeck = true;
        this.isInput = true; // 1.表单禁用
        // this.clqkForm = row
        this.$objCopy(row, this.clqkForm); //把当前要编辑的数据复制到数据域，给表单回显
        this.$message({ message: "成功打开", type: "success" });
      } else if (handle == "edit") {
        if (row.approveStatus != 2) {
          this.myDialogTitle = "产量情况报表编辑";
          this.ischeck = false;
          this.ischeckSh = false;
          this.isInput = false;
          this.$objCopy(row, this.clqkForm); //把当前要编辑的数据复制到数据域，给表单回显
        } else {
          this.dialogFormVisible = false;
          this.$message({ message: "已通过不可修改！", type: "error" });
        }
      } else if (handle == "add") {
        // this.clqkForm ={}
        this.$resetForm("clqkForm", this.clqkForm); //清空表单数据
        this.myDialogTitle = "产量情况报表填报";
        this.ischeck = false;
        this.ischeckSh = false;
        this.isInput = false;
      }
      // console.log(row);
    },
    uploadFiles() {
      this.importDialog = true;
      this.urlFile = "";
    },
    cancelUpload() {
      this.urlFile = "";
      this.fileList = [];
      this.importDialog = false;
    },
    //  监听改变
    handleChange(file, fileList) {
      this.fileList = fileList;
    },
    // 移除
    handleRemove(file, fileList) {
      this.fileList = fileList;
    },
    beforeAvatarUpload(file) {
      //1MB=1024*1024(1MB=1024KB 1KB=1024MB)
      const is10M = file.size / 1024 / 1024 < 10;
      //限制文件上传大小
      if (!is10M) {
        this.$message.error("上传图片大小不能超过 10MB!");
        return false;
      }
      return true;
    },
    //上传成功之后清除历史记录
    // handleSuccess(fileList) {
    //   this.fileList = [];
    //   this.$refs['fileForm'].upload.clearFiles()
    // },
    // 自定义上传Excel方法
    httpRequest(param) {
      // console.log(param.file);
      this.uploading = true;
      const File = this.fileList[0].raw;
      // const File = param.file
      console.log(File);
      // console.log(this.fileList);
      let formData = new FormData();
      formData.append("myfile", File);
      console.log(formData.get("myfile"));

      axios({
        url: "http://47.108.251.250:3296/api/fileAbout/fileUpload",
        method: "post",
        headers: {
          token: getToken(),
          "Content-Type": "multipart/form-data",
        },
        data: formData,
      }).then(
        (response) => {
          if (response.data.success === true && response.data.data !== "") {
            console.log(response.data);
            this.urlFile = response.data.data;
            console.log(this.urlFile);
            this.$message.success(response.data.message);
            param.onSuccess();
            this.uploading = false;
          } else {
            this.$message.error("上传失败");
          }
        },
        (error) => {
          console.log(error);
          this.$message.error(response.data.message);
        }
      );
    },
    //文件导入
    upload() {
      let formData = new FormData();
      formData.append("filePath", this.urlFile);
      console.log(formData.get("filePath"));
      axios({
        url: "http://47.108.251.250:3296/api/clqk/batchInput",
        method: "post",
        headers: {
          token: getToken(),
          "Content-Type": "multipart/form-data",
        },
        data: formData,
      }).then(
        (response) => {
          if (response.data.success === true) {
            console.log(response.data);
            this.$message.success(response.data.message);
            //刷新
            this.search();
            //关闭窗口
            this.importDialog = false;
            this.fileList = [];
          } else {
            this.$message.error("导入失败");
          }
        },
        (error) => {
          console.log(error);
          this.$message.error(response.data.message);
        }
      );
    },
    //删除行数据

    async handleDelete(row) {
      //判断是否可以删除
      if (row.approveStatus == 2) {
        //提示不能删除
        this.$message({ message: "已通过不可删除！", type: "error" });
      } else {
        //确认是否删除
        let confirm = await this.$myconfirm("确定要删除该数据吗?");
        console.log(confirm);
        if (confirm) {
          //发送删除请求
          console.log("111");
          let res = await clqkApi.delete({ id: row.id });
          console.log("222");
          console.log(res);
          //判断是否成功
          if (res.success) {
            //成功提示
            this.$message.success(res.message);
            //刷新
            this.search();
          } else {
            //失败提示
            this.$message.error(res.message);
          }
        }
      }
    },
    //批量删除
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(this.multipleSelection);
    },
    async handleBDelete() {
      //判断是否可以删除
      //确认是否删除
      let confirm = await this.$myconfirm("确定要删除该数据吗?");
      console.log(confirm);
      var ids = [];
      if (confirm) {
        for (let j = 0; j < this.multipleSelection.length; j++) {
          if (this.multipleSelection[j].approveStatus == 2) {
            //提示不能删除
            console.log(this.multipleSelection[j].approveStatus);
            this.$message({ message: "有已通过数据不可删除！", type: "error" });
            return;
          }
          ids[j] = this.multipleSelection[j].id;
        }
        console.log("ids", ids);
        // const ids = ids.toString();
        // console.log("ids",ids)
        //发送删除请求
        console.log("111");
        let res = await clqkApi.Bdelete(ids);
        console.log("222");
        console.log(res);
        //判断是否成功
        if (res.success) {
          //成功提示
          this.$message.success(res.message);
          //刷新
          this.search();
        } else {
          //失败提示
          this.$message.error(res.message);
        }
      }
    },
    /*** 当每页数量发生变化时触发该事件 */
    handleSizeChange(size) {
      console.log(size);
      this.pageSize = size;
      //将每页显示的数量交给成员变量
      this.search(this.pageNo, size);
    },
    /*** 当页码发生变化时触发该事件 */
    handleCurrentChange(page) {
      console.log(page);
      this.pageNo = page;
      //调用查询方法
      this.search(page, this.pageSize);
    },
    // 序号计算
    indexMethod(index) {
      // index默认在0开始，这里+1
      return index + 1 + (this.pageNo - 1) * this.pageSize;
    },
    // 获取当前日期
    filterTime() {
      var date = new Date();
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      this.currentTime = y + "-" + m + "-" + d;
    },
  },
};
</script>

<style lang="scss" scoped>
// 标题
.mytitle {
  font-size: large;
  padding-left: 10px;
  margin-bottom: 16px;
  float: left;
}

//按钮组
.myButtons {
  float: right;
}

//格子的样式
.bg-white {
  background: #ffffff;
}

.grid-content {
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
}

.calendar ::v-deep .el-button-group::before {
  display: none;
}

.calendar ::v-deep .el-button-group::after {
  display: none;
}

// 分割线样式
.el-divider--horizontal {
  display: block;
  height: 2px;
  width: 100%;
  margin: 24px 0;
}

// 表单各项的样式
.el-form-item {
  margin: 15px 10px 15px 10px;
}

//表单禁用字体样式
.el-input.is-disabled ::v-deep .el-input__inner {
  color: #606266;
}
//对话框宽度
// .customWidth{
//         width:80%;
//     }
::v-deep .saveAsDialog {
  width: 60% !important;
}

::v-deep .el-table .cell {
  overflow: unset;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 180px;
}

.el-input {
  width: 180px;
}
.tagstyle {
  cursor: pointer;
}
</style>